package com.lightswitch.smarttranslator.webserver;

import org.eclipse.jetty.server.Connector;
import org.eclipse.jetty.server.Handler;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.server.handler.ContextHandler;
import org.eclipse.jetty.server.handler.HandlerList;
import org.eclipse.jetty.server.handler.ResourceHandler;
import org.eclipse.jetty.server.nio.SelectChannelConnector;
import org.eclipse.jetty.servlet.ServletContextHandler;

/**
 *
 * @author quytp
 */
public class SmartTranslatorServer {
    public static void start() throws Exception {
        Server server = new Server(); 
        SelectChannelConnector connector = new SelectChannelConnector();
        connector.setPort(80);
        connector.setMaxIdleTime(30000);
        connector.setRequestHeaderSize(8192);
        server.setConnectors(new Connector[]{ connector });         
        ServletContextHandler servletHandler = new ServletContextHandler(ServletContextHandler.SESSIONS);
        servletHandler.setContextPath("/");
        servletHandler.addServlet("com.lightswitch.smarttranslator.webserver.controller.Index", "/*");
        
        ContextHandler resourceHandler = new ContextHandler("/content");
        resourceHandler.setResourceBase("c:/www/");
        resourceHandler.setHandler(new ResourceHandler());
        
        HandlerList handler = new HandlerList();
        handler.setHandlers(new Handler[] {resourceHandler, servletHandler});
        
        server.setHandler(handler);
        server.start();
        server.join();
    }
}
